package com.veryGood.service.Impl;

import com.veryGood.common.constant.Constants;
import com.veryGood.common.result.LayuiResultJson;
import com.veryGood.common.result.R;
import com.veryGood.domain.pojo.SupplierInfo;
import com.veryGood.mapper.SupMngMapper;
import com.veryGood.service.SupMngService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 供应商管理Service实现类
 */
@Service
public class SupMngServiceImpl implements SupMngService {

    @Autowired
    private SupMngMapper supMngMapper;

    //添加供应商
    public R addSup(SupplierInfo supplierInfo) {
        return R.success(supMngMapper.addSup(supplierInfo));
    }

    //查询所有的供应商
    @Override
    public LayuiResultJson findSupMngAll(Integer page, Integer limit) {
        LayuiResultJson layuiResultJson = new LayuiResultJson();
        Integer offset = (page - 1)*limit;
        Integer rows = limit;
        List<SupplierInfo> supplierInfos = supMngMapper.findSupList(offset,rows);
        layuiResultJson.setCode(Constants.OK);
        layuiResultJson.setMsg(Constants.MESSAGE_OK);
        Integer totalSize = supMngMapper.countSup();
        layuiResultJson.setCount(totalSize);
        layuiResultJson.setData(supplierInfos);
        return layuiResultJson;
    }

    //删除供应商
    @Override
    public R delSup(Integer id) {
        int result = supMngMapper.delSupId(id);
        if(result > 0 ){
            return R.success("删除成功！");
        }
        return R.error();
    }
}
